
package system.base;

import framework.core.*;
import system.SelectManager;
import system.data.*;

/*
	Author    :Wing
	CreateTime:2008-03-04 14:47:09
*/
public class WarehouseCustomer extends WarehouseCustomerBase 
{

//----system generated start----// 	
public WarehouseCustomer() 
{
	
}

private static void delete(DBConnection con,String id) throws Exception
{
    Conditions conditions = new Conditions();

    conditions.add(ID,id);
    
    delete(con,TABLE_NAME,conditions);
}
public static WarehouseCustomer fetch()
{
	return new WarehouseCustomer();
}
public static WarehouseCustomer copy(WarehouseCustomer srcObj)
{
	WarehouseCustomer obj = fetch();
	obj.copyBase(srcObj);
	return obj;
}
public static WarehouseCustomer fetch(DBConnection con,String id) throws Exception
{
    Conditions conditions = new Conditions();

    conditions.add(ID,id);
    
    return fetch(con,conditions);
}
public static WarehouseCustomer fetch(DBConnection con,Conditions conditions) throws Exception
{
	DBResult result = null;
	try
	{
		result = DBEngine.doSelect(con,"select * from " + TABLE_NAME,conditions);
		java.sql.ResultSet rs = result.getRs();
		WarehouseCustomer obj = null;
		if(rs.next())
		{
			obj = fetch(rs);
		}
		return obj;
	}
	finally
	{
		if(result!=null) result.clear() ;
	}
}
public static WarehouseCustomer fetch(java.sql.ResultSet rs) throws Exception
{
	WarehouseCustomer obj = new WarehouseCustomer();
	obj.initObject(rs);
	return obj;
}
protected void getUnique(DBConnection con) throws Exception
{
		setId(DBEngine.getId(con));
}
//----system generated end----//



//----add by wing start----//
public void beforeUpdate(DBConnection con) throws Exception
{
    setLastUpdateTime(new DateUtil().getFullString());      
}
public void beforeInsert(DBConnection con) throws Exception
{
    DateUtil du = new DateUtil();
    setCreateTime(du.getFullString());
    setLastUpdateTime(du.getFullString());
}  

public static boolean IsExistByCustomer(ObjectList warehCustomerList,Customer customer,String warehouseCode) throws Exception
{
    boolean menuExist = false;
    if(warehCustomerList != null || customer != null) {
        if (customer.getWarehouseCode().equals(warehouseCode)) {
            return true;
        } else {
            for(int i=0; i<warehCustomerList.size();i++){
                WarehouseCustomer warehouseCustomer = (WarehouseCustomer)warehCustomerList.get(i);
                if (warehouseCustomer.getCustomerCode().equals(customer.getCode())) return true;
            }
        }
    }
    return menuExist;
}

public static boolean IsExistByCustomer(ObjectList warehCustomerList,String customerCode) throws Exception
{
    boolean menuExist = false;
    if(warehCustomerList != null) {
        for(int i=0; i<warehCustomerList.size();i++){
            WarehouseCustomer warehouseCustomer = (WarehouseCustomer)warehCustomerList.get(i);
            if (warehouseCustomer.getCustomerCode().equals(customerCode)) return true;
        }
    }
    return menuExist;
}

public void deleteByWarehouseCode(DBConnection con,String warehouseCode) throws Exception
{
    Conditions conditions = new Conditions();

    conditions.add(WAREHOUSE_CODE,warehouseCode);
    
    delete(con,TABLE_NAME,conditions);
}
//----add by wing end----//
}

